#ifndef RP2LIGHT_H
#define RP2LIGHT_H

#include "Rp2Object.h"
#include "Rp2ColorRGB.h"
#include "Rp2Vector3.h"

namespace Rp2
{
class Light : public Object
{
	RP2_DECLARE_RTTI;
	RP2_DECLARE_NAME_ID;

public:
    enum LightType
    {
        LT_AMBIENT,
        LT_DIRECTIONAL,
        LT_POINT,
        LT_SPOT,
        LT_QUANTITY
    };

	Light(LightType eType);
	virtual ~Light();
	
    LightType Type;     // default: LT_AMBIENT

    // The colors of the light.
    ColorRGB Ambient;   // default: ColorRGB(0,0,0)
    ColorRGB Diffuse;   // default: ColorRGB(0,0,0)
    ColorRGB Specular;  // default: ColorRGB(0,0,0)

    // Attenuation is typically specified as a modulator
    //   m = 1/(C + L*d + Q*d*d)
    // where C is the constant coefficient, L is the linear coefficient,
    // Q is the quadratic coefficient, and d is the distance from the light
    // position to the vertex position.  To allow for a linear adjustment of
    // intensity, my choice is to use instead
    //   m = I/(C + L*d + Q*d*d)
    // where I is an "intensity" factor.
    float Constant;     // default: 1
    float Linear;       // default: 0
    float Quadratic;    // default: 0
    float Intensity;    // default: 1

    // Parameters for spot lights.  The cone angle must be in radians and
    // should satisfy 0 < Angle <= pi.
    float Angle;        // default: pi
    float CosAngle;     // default: -1
    float SinAngle;     // default:  0
    float Exponent;     // default:  1

    // A helper function that lets you set Angle and have CosAngle and
    // SinAngle computed for you.
    void SetAngle (float fAngle);

    // Although the standard directional and spot lights need only a direction
    // vector, to allow for new types of derived-class lights that would use
    // a full coordinate frame, Light provides storage for such a frame.  The
    // light frame is always in world coordinates.
    //   default position  P = (0,0,0)
    //   default direction D = (0,0,-1)
    //   default up        U = (0,1,0)
    //   default right     R = (1,0,0)
    // The set {D,U,R} must be a right-handed orthonormal set.  That is, each
    // vector is unit length, the vectors are mutually perpendicular, and
    // R = Cross(D,U).
    Vector3f Position, DVector, UVector, RVector;

    // A helper function that lets you set the direction vector and computes
    // the up and right vectors automatically.
    void SetDirection (const Vector3f& rkDirection);

    // This is for debug mode to allow you to check if the coordinate frame
    // vectors form a right-handed orthonormal set.
    bool IsValidFrame () const;

protected:
	Light();

private:
	static const char* ms_aacType[LT_QUANTITY];
};

typedef Pointer<Light> LightPtr;
}

#endif